#!/usr/bin/env python#coding:utf-8from django.shortcuts import render,render_to_response,HttpResponsefrom app01.Helper import Checkcodeimport StringIOdef CheckCode(request): mstream = StringIO.StringIO() validate_code = Checkcode.create_validate_code() img = validate_code[0] img.save(mstream, "GIF") #将验证码保存到session request.session["CheckCode"] = validate_code[1] return HttpResponse(mstream.getvalue()) def Login(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('pwd') check_code = request.POST.get('checkcode') #从session中获取验证码 session_code = request.session["CheckCode"] if check_code.strip().lower() != session_code.lower(): return HttpResponse('验证码不匹配') else: return HttpResponse('验证码正确') return render_to_response('login.html',{'error':"",'username':'','pwd':'' })
评论